package com.reebake.ideal.org.controller;

import com.reebake.ideal.model.TreeNode;
import com.reebake.ideal.org.entity.OrganizationDepartment;
import com.reebake.ideal.org.service.OrganizationDepartmentService;
import com.reebake.ideal.org.util.DepartmentUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 部门控制层
 */
@Tag(name = "部门对象功能接口")
@RestController
@RequestMapping("/organization/department")
public class OrganizationDepartmentPlusController {
    @Autowired
    private OrganizationDepartmentService organizationDepartmentService;

    /**
     * 查询部门树
     *
     * @return 部门树
     */
    @Operation(summary = "查询部门树")
    @PostMapping("tree")
    public List<TreeNode> tree() {
        List<OrganizationDepartment> departments = organizationDepartmentService.list();
        return DepartmentUtil.toTree(departments);
    }
}
